﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace Common.Tools
{
   public static class EmailHelper
    {
        /// <summary>
        /// 发送邮件  刘彻
        /// </summary>
        /// <param name="content"></param>
        /// <param name="sendTo"></param>
        /// <param name="title"></param>
        /// <param name="attachmentPath"></param>
        /// <returns></returns>
        public static bool SendEmail(string sendTo, string title, string content, string attachmentPath)
        {
            try
            {
                string host = "smtp.163.com";
                int port = 25;
                bool ssl = false;
                string loginname = "seajoan_com@163.com";
                string password = "";
                var mail = new Tool.Mail();
                mail.SmtpServer.Host = host;
                mail.SmtpServer.Port = port;
                mail.SmtpServer.EnableSsl = ssl;
                mail.SmtpServer.Credentials = new NetworkCredential(loginname, password);
                var list = new ArrayList();
                //如果有附件
                if (Tool.StringUnit.IsNotNullOrEmpty(attachmentPath))
                {
                    list.Add(attachmentPath);
                }
                else
                {
                    list = null;
                }
                mail.SendMail(sendTo, title, content, loginname, list);
                return true;
            }
            catch (Exception ex)
            {
                Tool.Log.WriteError(ex.ToString());
                return false;
            }
        }
    }
}
